<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>新增人员</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" :rules="formRules">
            <el-row :gutter="10">
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="name">
                  <div>账号</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="pwd">
                  <div>密码</div>
                  <el-input v-model="data.pwd" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="real_name">
                  <div>人员名称</div>
                  <el-input v-model="data.real_name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="phone">
                  <div>电话</div>
                  <el-input v-model="data.phone" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="phone2">
                  <div>备用电话</div>
                  <el-input v-model="data.phone2" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="email">
                  <div>电子邮件</div>
                  <el-input v-model="data.email" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="status">
                  <div>状态</div>
                  <el-select v-model="data.status" placeholder="请选择" size="mini">
                    <el-option v-for="(item, index) in plansStatus" :key="index" :label="item.name" :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="department_id">
                  <div>部门</div>
                  <v-select v-model="data.department_id" action="departmentList" :query="{category: 1}" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="section_id">
                  <div>科室</div>
                  <v-select v-model="data.section_id" :disabled="!data.department_id" :query="{parent_id:data.department_id}" action="departmentList" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="class_id">
                  <div>班组</div>
                  <v-select v-model="data.class_id" :disabled="!data.section_id" :query="{parent_id:data.section_id}" action="departmentList" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="job_id">
                  <div>岗位</div>
                  <v-select v-model="data.job_id" :disabled="!data.class_id" :query="{parent_id:data.class_id}" action="departmentList" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="type">
                  <div>账号类型</div>
                  <el-select v-model="data.type" placeholder="请选择" size="mini">
                    <el-option v-for="(item, index) in staffType" :key="index" :label="item.name" :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="profession">
                  <div>专业</div>
                  <el-select v-model="data.profession" placeholder="请选择" size="mini">
                    <el-option v-for="(item, index) in staffProfession" :key="index" :label="item.name" :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row>
                <el-col :span="24">
                  <Tinymce id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import API from '@/api/personnel/staff'
import Tinymce from '@/components/Tinymce/index'
import { plansStatus, staffType, staffProfession } from '@/utils/options'
import VSelect from '@/components/select'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    Tinymce,
    VSelect
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        sort: '100'
      },
      plansStatus,
      staffType,
      staffProfession,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入账号',
            trigger: 'blur'
          }
        ],
        pwd: [
          {
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }
        ],
        real_name: [
          {
            required: true,
            message: '请输入人员名称',
            trigger: 'blur'
          }
        ],
        status: [
          {
            required: true,
            message: '请选择状态',
            trigger: 'change'
          }
        ],
        department_id: [
          {
            required: true,
            message: '请选择部门',
            trigger: 'change'
          }
        ],
        section_id: [
          {
            required: true,
            message: '请选择工段',
            trigger: 'change'
          }
        ],
        job_id: [
          {
            required: true,
            message: '请选择岗位',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  watch: {},
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/personnel/staff')
    }
  }
}
</script>
